﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Ext.Net;

using VTV.TaskManagementSystem.Entities;
using VTV.TaskManagementSystem.BusinessLogic;
using VTV.TaskManagementSystem.Common;

namespace VTV.TaskManagementSystem.WebApp
{
    public partial class Default_Ver2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                if (Request.QueryString["team"] != null)
                {
                    string teamName = Request.QueryString["team"];
                    if (Request.QueryString["startdate"] != null && Request.QueryString["enddate"] != null)
                    {
                        var startDate = Convert.ToDateTime(Request.QueryString["startdate"]);
                        var endDate = Convert.ToDateTime(Request.QueryString["enddate"]);
                        this.literalMain.Text = RenderHTML.Tasks(startDate <= endDate ?
                            new BusinessLogic.TaskTeam().GetDefaultToShow(DateTime.Today, teamName, startDate, endDate) :
                            new BusinessLogic.TaskTeam().GetDefaultToShow(DateTime.Today, teamName, null, null));
                    }
                    else
                    {
                        this.literalMain.Text = RenderHTML.Tasks(new BusinessLogic.TaskTeam().GetDefaultToShow(DateTime.Today, teamName, null, null));
                    }
                }
                else
                {
                    if (Request.QueryString["startdate"] != null && Request.QueryString["enddate"] != null)
                    {
                        var startDate = Convert.ToDateTime(Request.QueryString["startdate"]);
                        var endDate = Convert.ToDateTime(Request.QueryString["enddate"]);
                        this.literalMain.Text = RenderHTML.Tasks(startDate <= endDate ?
                            new BusinessLogic.TaskTeam().GetDefaultToShow(DateTime.Today, null, startDate, endDate) :
                            new BusinessLogic.TaskTeam().GetDefaultToShow(DateTime.Today, null, null, null));
                    }
                    else
                    {
                        this.literalMain.Text = RenderHTML.Tasks(new BusinessLogic.TaskTeam().GetDefaultToShow(DateTime.Today, null, null, null));
                    }
                }
            }
        }
    }
}